//
//  MasonryCell.m
//  cell
//
//  Created by Sich on 16/11/28.
//  Copyright © 2016年 sicuihuan. All rights reserved.
//

#import "MasonryCell.h"
#import "Masonry.h"

@implementation MasonryCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI{
    UIView *backView = [[UIView alloc] init];
    [self.contentView addSubview:backView];
    
    UILabel *lab;
    for (int i=0; i<3; i++) {
        UILabel *label = [[UILabel alloc] init];
        label.numberOfLines = 0;
        label.layer.borderColor = [UIColor greenColor].CGColor;
        label.layer.borderWidth = 2.0;
        label.text = [self randomText];
        label.textAlignment = NSTextAlignmentLeft;
        label.textColor = [self randomColor];
        [backView addSubview:label];
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            if (lab) {
               make.top.mas_equalTo(lab.mas_bottom).offset(10);
            }else{
                make.top.mas_equalTo(backView.mas_top).offset(10);
                
            }
            make.left.mas_equalTo(self.contentView.mas_left).offset(15);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
            
        }];
        
        lab = label;
        
    }
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
        make.bottom.equalTo(lab.mas_bottom).offset(0);
    }];
    
    
}
- (UIColor *)randomColor {
    CGFloat hue = ( arc4random() % 256 / 256.0 );  //  0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}

- (NSString *)randomText {
    CGFloat length = arc4random() % 50 + 5;
    
    NSMutableString *str = [[NSMutableString alloc] init];
    for (NSUInteger i = 0; i < length; ++i) {
        [str appendString:@"测试数据很长，"];
    }
    
    return str;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
